<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Order extends Model
{
    use SoftDeletes;

    /**
     * 可以被批量赋值的属性.
     *
     * @var array
     */
    protected $fillable = ['phone','name','start','start_address','start_lat','start_lng',
        'end','end_address','end_lat','end_lng','date',
    ];

    protected $dates = ['created_at', 'updated_at'];



    public static function getNewOrderCode() {
        $order_no = date('Ymd').substr(time(),-5).substr(microtime(),2,5);
        return $order_no;
    }

    public function member() {
        return $this->belongsTo(Member::class);
    }

    public function driver() {
        return $this->belongsTo(Driver::class);
    }

    public function getStatusTextAttribute() {
        $status = $this->status;
        switch ($status) {
            case -3:
                return '无法出票';
                break;
            case -2:
                return '支付失败';
                break;
            case -1:
                return '取消';
                break;
            case 0:
                return '待出票';
                break;
            case 1:
                return '待支付';
                break;
            case 2:
                return '已支付';
                break;
            case 3:
                return '已结束';
                break;
            default:
                return '未知';
        }
    }
}
